<!DOCTYPE html>
<html>
<head>
<title>Circuit Diagram Fig. 6.1</title>
</head>
<body>
<canvas id="circuitCanvas" width="500" height="450"></canvas>
<script>
    const canvas = document.getElementById('circuitCanvas');
    const ctx = canvas.getContext('2d');

    // Style settings
    ctx.lineWidth = 2;
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';
    ctx.font = '24px Arial';
    ctx.textAlign = 'center';
    ctx.textBaseline = 'middle';

    // Define coordinates for the main rectangular loop
    const leftX = 80;
    const rightX = 420;
    const topY = 100;
    const bottomY = 300;

    // --- Draw Wires ---

    // Top wire segments (around capacitor)
    const capCenterX = (leftX + rightX) / 2;
    const capGap = 20;
    const capPlateX1 = capCenterX - capGap / 2;
    const capPlateX2 = capCenterX + capGap / 2;
    ctx.beginPath();
    ctx.moveTo(leftX, topY);
    ctx.lineTo(capPlateX1, topY);
    ctx.moveTo(capPlateX2, topY);
    ctx.lineTo(rightX, topY);
    ctx.stroke();

    // Bottom wire segments (around resistor)
    const resCenterX = (leftX + rightX) / 2;
    const resWidth = 100;
    const resX1 = resCenterX - resWidth / 2;
    const resX2 = resCenterX + resWidth / 2;
    ctx.beginPath();
    ctx.moveTo(leftX, bottomY);
    ctx.lineTo(resX1, bottomY);
    ctx.moveTo(resX2, bottomY);
    ctx.lineTo(rightX, bottomY);
    ctx.stroke();

    // Right side wire
    ctx.beginPath();
    ctx.moveTo(rightX, topY);
    ctx.lineTo(rightX, bottomY);
    ctx.stroke();

    // Left side wire segments (around switch)
    const switchCenterY = (topY + bottomY) / 2;
    const switchGap = 60;
    const switchY1 = switchCenterY - switchGap / 2;
    const switchY2 = switchCenterY + switchGap / 2;
    ctx.beginPath();
    ctx.moveTo(leftX, topY);
    ctx.lineTo(leftX, switchY1);
    ctx.moveTo(leftX, switchY2);
    ctx.lineTo(leftX, bottomY);
    ctx.stroke();

    // --- Draw Components ---

    // Capacitor (C)
    const capPlateHeight = 40;
    ctx.beginPath();
    ctx.moveTo(capPlateX1, topY - capPlateHeight / 2);
    ctx.lineTo(capPlateX1, topY + capPlateHeight / 2);
    ctx.moveTo(capPlateX2, topY - capPlateHeight / 2);
    ctx.lineTo(capPlateX2, topY + capPlateHeight / 2);
    ctx.stroke();
    ctx.fillText('C', capCenterX, topY - 35);

    // Resistor (R)
    const resHeight = 20;
    ctx.beginPath();
    ctx.rect(resX1, bottomY - resHeight / 2, resWidth, resHeight);
    ctx.stroke();
    ctx.fillText('R', resCenterX, bottomY + 35);
    
    // Switch (open)
    const switchArmLength = 40;
    const switchAngle = -Math.PI / 4; // 45 degrees up-left
    ctx.beginPath();
    ctx.moveTo(leftX, switchY2);
    ctx.lineTo(leftX + switchArmLength * Math.cos(switchAngle), switchY2 + switchArmLength * Math.sin(switchAngle));
    ctx.stroke();
    // Small circles for terminals
    ctx.beginPath();
    ctx.arc(leftX, switchY1, 3, 0, 2 * Math.PI);
    ctx.fill();
    ctx.beginPath();
    ctx.arc(leftX, switchY2, 3, 0, 2 * Math.PI);
    ctx.fill();


    // --- Draw Figure Label ---
    ctx.font = 'bold 24px Arial';
    ctx.fillText('Fig. 6.1', canvas.width / 2, 400);

</script>
</body>
</html>